<?php
/* 定义属性 */
define ("CONfilename", "../config/set.php");
define ("DDUDB","../class/db.class.php");
define ("LOADINDEX","../class/load.class.php");
/* 為系統作配置準備，方便以後系統引用數據庫 */
session_start();
require_once(CONfilename);/*讀設置*/
require_once(DDUDB);/* 載入數據庫模塊 */
require_once(LOADINDEX);/* 載入引導模塊 */
require './model.php';

/* 配置屬性 */
$returnajaxcontent ="";
/*下面建立數據連接，添加數據庫模塊到變量，使db變量可以直接控制sql。  */
$db = new CDB();
$MEMBER = new member();
$ROOT = new root();
$MODEL = new model();
/* 收到信息 */
if(!empty($_GET)){
	$action = $_GET['action'];
	switch ($action){
		case 'showhj':
			roadter($action);
			break;
		case 'showtj':
			roadter($action);
			break;
		case 'listhj':
			listthj($_POST,1);
			break;
		case 'listtj':
			listthj($_POST,2);
			break;
		case 'thjadd':
			include './npfe_thj_add.html';
			break;
		case 'loadhjtp':
			if (!empty($_GET['link'])){
				loadhjtemp($_GET['link']);
			}else {
				loadhjtemp();
			}
			break;
		case 'loadtjtp':
			if (!empty($_GET['link'])){
				loadtjtemp($_GET['link']);
			}else {
				loadtjtemp();
			}
			break;
		case 'hjaddsubmit':
			addhjc($_POST);
			break;
		case 'tjaddsubmit':
			addtjc($_POST);
			break;
		case 'hjaddreview':
			reviewhjc($_POST);
			break;
		case 'tjaddreview':
			reviewtjc($_POST);
			break;
		case 'viewrfs':
			if (isset($_GET['snid']) && isset($_GET['time'])){
				viewrfs($_GET['snid'],$_GET['time']);
			}else {
				echo '参数错误';
			}
			break;
	}
}
function getdmt(){
	$y=date("Y",time());
	$m=date("m",time());
	$d=date("d",time());
	$t0=date('t');           // 本月一共有几天
	$t1=mktime(0,0,0,$m,1,$y);        // 创建本月开始时间
	$t2=mktime(23,59,59,$m,$t0,$y);       // 创建本月结束时间
	$rdate['today'] = date("Y-m-d",time());
	$rdate['dmtb'] = date("Y-m-d H:i:s",$t1);
	$rdate['dmte'] = date("Y-m-d H:i:s",$t2);
	$rdate['sjc'] = $t2-$t1;
	return $rdate;
}
function formattime($stt,$ett){
	$formated['stt'] = date('Y-m-d H:i:s',strtotime($stt));
	$formated['ett'] = date('Y-m-d H:i:s',strtotime($ett));
	return $formated;
}
function roadter($rtp){
	//使用地址路由将同样的页面内容分配多个不同的信息获取路径
	$str = file_get_contents('./djhjtj.html');
	switch ($rtp){
		case 'showhj':
			$stt['{listroadter}'] = 'listhj';
			$stt['{title}'] = '售后处理-换货';
			$stt['{searchbutton}'] = 'checkhjsubmit()';
			break;
		case 'showtj':
			$stt['{listroadter}'] = 'listtj';
			$stt['{title}'] = '售后处理-退货';
			$stt['{searchbutton}'] = 'checktjsubmit()';
			break;
			
		default:
			$stt['{listroadter}'] = 'listhj';
			$stt['{title}'] = '无法获取';
			break;
	}
	$roadter = strtr($str, $stt);
	echo $roadter;
}
function loadtjtemp($link = NULL){
	global $MEMBER;
	global $db;
	$now_em = $MEMBER->getnickname($_SESSION['uid']);
	$tp = file_get_contents('./npfe_thj_tjd.html');
	$stt = array(
			'{sman}' => '<input class="easyui-textbox" type="text" name="sman" id="sman" data-options="required:true" style="width:80%">',
			'{orderdate}' => '<input class="easyui-datetimebox" name="orderdate" id="orderdate" style="width:100px" />',
			'{snid}' => '<input class="easyui-textbox" type="text" name="snid" id="tjtpsnid" data-options="required:true" style="width:80%">',
			'{shixian}' => '<select class="easyui-combobox" name="shixian"><option value="7天内">7天内</option><option value="7至15天内">7至15天内</option><option value="超过15天">超过15天</option></select>',
			'{liyou}' => '<select class="easyui-combobox" name="liyou"><option value="产品质量">产品质量</option><option value="销售误导">销售误导</option><option value="同价异款">同价异款</option><option value="异价异款">异价异款</option></select>',
			'{cnumber}' => '<input class="easyui-textbox" type="text" name="cnumber" data-options="required:true">',
			'{cname}' => '<input class="easyui-textbox" type="text" name="cname" data-options="required:true">',
			'{o_cellphone}' => '<input class="easyui-textbox" type="text" name="o_cellphone" data-options="required:true">',
			'{o_sn}' => '<input class="easyui-textbox" type="text" name="o_sn" data-options="required:true">',
			'{n_cellphone}' => '<input class="easyui-textbox" type="text" name="n_cellphone" data-options="required:true">',
			'{n_sn}' => '<input class="easyui-textbox" type="text" name="n_sn" data-options="required:true">',
			'{n_address}' =>'<input class="easyui-textbox" type="text" name="n_address" data-options="required:true" style="width:90%">',
			'{fanying}' => '<input class="easyui-textbox" name="fanying" data-options="multiline:true" style="width:100%;height:200px;">',
			'{jieshi}' => '<input class="easyui-textbox" name="jieshi" data-options="multiline:true" style="width:100%;height:200px;">',
			'{chajia}' => '<input class="easyui-textbox" type="text" name="chajia" data-options="required:true">',
			'{shoukuaidi}' => '<input class="easyui-textbox" type="text" name="shoukuaidi" data-options="required:true">',
			'{jikuaidi}' => '<input class="easyui-textbox" type="text" name="jikuaidi" data-options="required:true">',
			'{msc}' => '打印或预览时生成',
			'{mss}' => '打印或预览时生成',
			'{msj}' => '打印或预览时生成',
	);
	if (!empty($link)) {
		$info = model::findlinkgd($link);
		$stt['{cnumber}'] = '<input class="easyui-textbox" type="text" name="cnumber" data-options="required:true" value="'.$link.'" />';
		$stt['{cname}'] = '<input class="easyui-textbox" type="text" name="cname" data-options="required:true" value="'.$info['cname'].'" />';
		$stt['{fanying}'] = '<input class="easyui-textbox" name="fanying" data-options="multiline:true" value="'.$info['fanying'].'" style="width:100%;height:200px;"/>';
	}
	$stt['{ctldate}'] = date('Y-m-d',time());
	$stt['{ctlman}'] = $now_em;
	$tp = strtr($tp, $stt);
	echo $tp;
}


function viewrfs($snid = 0,$time){
	
}
function reviewhjc($posti){
	global $MEMBER;
	global $MODEL;
	$now_em = $MEMBER->getnickname($_SESSION['uid']);
	$orderdate = date('Y-m-d H:i:s',strtotime($posti['orderdate']));
	$snid = $posti['snid'];
	$tp = file_get_contents('./npfe_thj_hjd.html');
	$stt = array(
			'{orderdate}' => $orderdate,
			'{snid}' => $snid,
			'{shixian}' => $posti['shixian'],
			'{liyou}' => $posti['liyou'],
			'{cnumber}' => $posti['cnumber'],
			'{cname}' => $posti['cname'],
			'{o_cellphone}' => $posti['o_cellphone'],
			'{o_sn}' => $posti['o_sn'],
			'{n_cellphone}' => $posti['n_cellphone'],
			'{n_sn}' => $posti['n_sn'],
			'{n_address}' => $posti['n_address'],
			'{fanying}' => $posti['fanying'],
			'{chajia}' => $posti['chajia'],
			'{shoukuaidi}' => $posti['shoukuaidi'],
			'{jikuaidi}' => $posti['jikuaidi'],
			'{msc}' => $MODEL->getMoneyString($posti['chajia']),
			'{mss}' => $MODEL->getMoneyString($posti['shoukuaidi']),
			'{msj}' => $MODEL->getMoneyString($posti['jikuaidi']),
	);
	$stt['{ctldate}'] = date('Y-m-d',time());
	$stt['{ctlman}'] = $now_em;
	$tp = strtr($tp, $stt);
	echo $tp;
	try {
		$pf = fopen('./print_doc/'.$snid.'.htm', 'w');
		$htm = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>换机单打印</title>
</head><body>'.$tp.'
</body>
</html>';
		fwrite($pf, $htm);
		fclose($pf);
	} catch (Exception $e) {
		if ($e->g=="") {
			print $e->getMessage();
		}
	}
}
function reviewtjc($posti){
	global $MEMBER;
	global $MODEL;
	$now_em = $MEMBER->getnickname($_SESSION['uid']);
	$orderdate = date('Y-m-d H:i:s',strtotime($posti['orderdate']));
	$snid = $posti['snid'];
	$tp = file_get_contents('./npfe_thj_tjd.html');
	$stt = array(
			'{orderdate}' => $orderdate,
			'{snid}' => $snid,
			'{sman}' => $posti['sman'],
			'{shixian}' => $posti['shixian'],
			'{cnumber}' => $posti['cnumber'],
			'{cname}' => $posti['cname'],
			'{o_cellphone}' => $posti['o_cellphone'],
			'{o_sn}' => $posti['o_sn'],
			'{fanying}' => $posti['fanying'],
			'{jieshi}' => $posti['jieshi'],
			'{chajia}' => $posti['chajia'],
			'{shoukuaidi}' => $posti['shoukuaidi'],
			'{msc}' => $MODEL->getMoneyString($posti['chajia']),
			'{mss}' => $MODEL->getMoneyString($posti['shoukuaidi']),
	);
	$stt['{ctldate}'] = date('Y-m-d',time());
	$stt['{ctlman}'] = $now_em;
	$tp = strtr($tp, $stt);
	echo $tp;
	try {
		$pf = fopen('./print_doc/'.$snid.'.htm', 'w');
		$htm = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>退机单打印</title>
</head><body>'.$tp.'
</body>
</html>';
		fwrite($pf, $htm);
		fclose($pf);
	} catch (Exception $e) {
		if ($e->g=="") {
			print $e->getMessage();
		}
	}
}